﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GridExportHelper.cs" company="">
//   
// </copyright>
// <summary>
//   The grid export helper.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace NetworkSupervisor.Helper
{
    using System;
    using System.Diagnostics;
    using System.Windows.Forms;

    using DevExpress.XtraEditors;
    using DevExpress.XtraGrid;

    /// <summary>The grid export helper.</summary>
    public static class GridExportHelper
    {
        #region Public Methods and Operators

        /// <summary>导出GridControl为Excel</summary>
        /// <param name="gridControl">The grid Control.</param>
        /// <param name="fileName">文件名称，示例："在线情况统计列表"</param>
        public static void ExportGridToExcel(GridControl gridControl, string fileName)
        {
            SaveFileDialog f = new SaveFileDialog();
            f.Filter = "Excel(*.xls)|*.xls";
            f.FileName = fileName + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + ".xls";
            if (f.ShowDialog() == DialogResult.OK)
            {
                gridControl.ExportToXls(f.FileName);
                if (XtraMessageBox.Show("导出成功，是否打开？", string.Empty, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    gridControl.BeginInvoke(new MethodInvoker(() => Process.Start(f.FileName)));
                }
            }
        }

        #endregion
    }
}